/**
 * Slot Machine, July 2012
 *
 * Owner: Rami Abou Ghanem
 * Owner: Sumbul Alvi
 *
 */

package Backend;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class SlotMachine {
	private SlotsInfo slots;
	private UserCoins userCoins;
	private int betAmount;
	private int numOfLines;
	private int winnings;
	
	public SlotMachine(int numSlots)
	{
		slots = new SlotsInfo(numSlots);
		userCoins = new UserCoins();
	}
	
	//Generates the slots and checks for wins
	public void spin()
	{
		slots.generateSlots();
		slots.display();
		winnings = betAmount * slots.checkSlotsForWin(numOfLines);
	}
	
	//Set amount to bet
	public void bet(int numLines, int bets)
	{
		numOfLines = numLines;
		betAmount = bets;
		userCoins.removeCoins(betAmount * numOfLines);
	}
	
	//Add winnings to userCoins
	public void addWinnings()
	{
		userCoins.addCoins(winnings);
	}
	
	public int getWinnings()
	{
		return userCoins.getCoins();
	}
	
	public void display()
	{
		System.out.println("Bet: " + betAmount + " Win: " + winnings + " Coins: " + userCoins.getCoins());
	}
	
	public static void main(String[] args) throws NumberFormatException, IOException
	{
		int bet, lines;
		SlotMachine machine = new SlotMachine(3);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		machine.display();
		
		while(machine.getWinnings() > 0)
		{
			System.out.print("Enter amount to bet: ");
			bet = Integer.parseInt(br.readLine());
			System.out.print("Enter number of lines: ");
			lines = Integer.parseInt(br.readLine());
			machine.bet(lines, bet);
			
			machine.display();
			machine.spin();
			machine.addWinnings();
			machine.display();
		}
	}

}
